package net.intellect.collectPro.main;

import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;

import net.intellect.collectPro.businessLogic.CycleAssignment;
import net.intellect.force.ClientSalesforce;

import com.sforce.soap.enterprise.InvalidIdFault;
import com.sforce.soap.enterprise.LoginFault;
import com.sforce.soap.enterprise.UnexpectedErrorFault;

public class CyCleAssignment {

	protected static Logger logger = Logger.getLogger("assignment");

	/**
	 * Executes the Assignment process. 
	 * @param args [user, password, token, enterprise, cycle]
	 * Format:
	 * - enterprise (External Id)
	 * - cycle (External Id)
	 */
	public static void main(String[] args) throws UnexpectedErrorFault, InvalidIdFault, LoginFault, RemoteException, Exception{
		logger.getLevel();
		if (args.length == 5) {
			String userName = args[0]; 
			String password = args[1]; 
			String token = args[2]; 
			String enterprise = args[3]; 
			String cycle = args[4];
	
			try {
				if (null != userName && null != password && null != token && null != enterprise && null != cycle) {
					ClientSalesforce.setLoginValues(userName,password,token);
					ClientSalesforce.login();
					CycleAssignment cycleAssignment = new CycleAssignment();
					cycleAssignment.assignCycle(enterprise, cycle);
				}
			} catch (Exception e) {
				logger.log(Level.SEVERE, "net.intellect.collectPro.main.CyCleAssignment/"+"Error: " + e);
			}
		} else {
			logger.log(Level.SEVERE, "net.intellect.collectPro.main.CyCleAssignment/"+"Required information was not received");
		}
	}

}
